import com.google.common.base.Joiner;
import com.google.common.collect.Lists;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;

/**
 * @author chenxin
 * @time 2017-03-03-23:58
 */
public class StringTest {
    static HashMap map = new HashMap();

    private static char startChar = 'A';

    private static char endChar = 'z';

    private static int offset = endChar - startChar + 1;

    private static int dup = 0;

    private static volatile java.lang.Object name_;

    public static void main(String[] args) {
        String areaIds = "2004895,2306,2179,1028,2004890,2010650,2001305,3082,2003860,2004628,2001682,2005523,3088,2001678,2007822,2007821,2003850,2069,2965,6038,3609,5149,34,2007868,2006203,2002107,3110,2010679,2002739,2001584,2004784,2005424,3119,3120,2011950,2010664,5558,2008868,2005664,2005466,4422,2008022,2004305,2010446,2129,3283,2133,2007755,1750,2006727,1754,603,6363,2007749,6364,6365,2006977,2002113,2145,6754,6755,2001658,2004475,2008184,2007673,2008822,2008821,2006898,2001394,2029,2005875,2030,2001393,2004206,2008815,2010476,2008813,2001643,2007784,2000102,2000103,2003172,2682,3066,2006244,2043,3451,2000101,5755,3452,2008930,3068,3069,2000096,2004321,2012641";
        String union = "5558,5755,1028,2004890,2005466,2010650,2008022,3082,2003860,3088,2010446,2007821,2003850,2133,2007755,3609,2006727,1754,603,6363,2007749,5149,6365,2006977,34,2007868,2001658,2006203,2007673,2008821,2006898,3120,2011950,2008815,2008813,2000102,2003172,2008868,2043,3451,3452,2008930,2005664,2004321,2004895,2306,2179,2001305,2004628,2001682,2005523,2001678,2007822,2069,2965,6038,2002107,3110,2010679,2002739,2001584,2004784,2005424,3119,2010664,4422,2004305,2129,3283,1750,6364,2002113,2145,6754,6755,2004475,2008184,2008822,2001394,2029,2005875,2030,2001393,2004206,2010476,2001643,2007784,2000103,2682,3066,2006244,2000101,3068,3069,2000096,2012641";
        System.out.println(sort(areaIds));
        System.out.println(sort(union));

    }

    private static Set<Long> sort(String areaIds) {
        final List<Long> collect = Arrays.stream(areaIds.split(",")).map(Long::valueOf).collect(Collectors.toList());
        Set<Long> treeset = new TreeSet<>(collect);
        return treeset;
    }

    private static void testListJoinToString() {
        List<Integer> list = Lists.newArrayList(1, 2, 3);
        String s = Joiner.on(",").join(list); // 以逗号分割
        System.out.println(s);
    }

    private static void testModify() {
        Integer x = 1;
        name_ = x;
    }

    private static void tryBit(char[] chars, int i) {
        for (char j = startChar; j <= endChar; j++) {
            chars[i - 1] = j;
            if (i > 1)
                tryBit(chars, i - 1);
            else
                test(chars);
        }
    }

    private static void testEqual(){
        System.out.println("abc"==String.valueOf("abc"));
    }

    private static void test(char[] chars) {

//        String str = new String(chars).replaceAll("[^a-zA-Z_]", "").toUpperCase();// 195112:0
        String str = new String(chars).toLowerCase();//195112:6612
        //String str = new String(chars).replaceAll("[^a-zA-Z_]","");//195112:122500
        //String str = new String(chars);//195112:138510
        int hash = str.hashCode();
        if (map.containsKey(hash)) {
            String s = (String) map.get(hash);
            if (!s.equals(str)) {
                dup++;
                System.out.println(s + ":===" + str);
            }
        } else {
            map.put(hash, str);
            // System.out.println(str);
        }
    }
}
